package org.openotdr.server;

import org.openotdr.server.otdr.Sr4731Parser;

public class CsvParser {
    private Sr4731Parser parser;

    public CsvParser(Sr4731Parser parser) {
        this.parser = parser;
    }
    
    public String toCsv() {
        String csv = "";
        
        csv += createLine("Wavelength", parser.getWavelength().toString());
        csv += createLine("Distance Range", parser.getDistanceRange().toString());
        csv += createLine("Pulse Width", parser.getPulseWidth().toString());
        csv += createLine("Sampling Point", parser.getSamplingPoints().toString());
        csv += createLine("Average Time", parser.getAverage().toString());
        csv += createLine("IOR", parser.getIor().toString());
        csv += createLine("BSC", parser.getBsc().toString());
        csv += createArray(parser.getTraceInDB());
        return csv;
    }

    private String createArray(double[] trace) {
        String ret = "";
        for (Double d : trace) {
            ret += d.toString() + getDelimiter();
        }
        return ret;
    }

    private String createLine(String caption, String value) {
        return caption + "," + value + getDelimiter();
    }

    private String getDelimiter() {
        return "<BR>";
    }
}
